// pages/user/allDynamic/allDynamic.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listArr: [],
    pageNum: '1',//分页
    imgURL: app.globalData.imgURL,//图片总路径
  },

  //图片点击
  imgClick: function (e) {
    var that = this;
    console.log(e);
    console.log(e.currentTarget.id);
    console.log(e.currentTarget.dataset.hang);
    var imgArr = that.data.listArr[e.currentTarget.id].img_url;
    var nImgArr = new Array();
    for (var i = 0; i < imgArr.length; i++) {
      nImgArr[i] = that.data.imgURL + imgArr[i].replace('_thum', '');
    }
    wx.previewImage({
      current: nImgArr[e.currentTarget.dataset.hang],
      urls: nImgArr,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },

  getData:function(){
    var that = this;
    app.post('act/listForMy', {
      pageNum: that.data.pageNum, openId: wx.getStorageSync('userInfo').userId}).then((res) => {
      console.log('success');
      console.log(res);
      if (res.code == 0) {
        var result = res.resultData;
        for (var i = 0; i < result.length; i++) {
          result[i].img_url = result[i].img_url.split(',');
        }

        console.log(result);
        that.setData({
          listArr: that.data.listArr.concat(result),
        })
      } else {
        wx.showModal({
          title: '温馨提示',
          content: res.msg,
          showCancel: false,
        })
      }
    }).catch((errMsg) => {
      console.log('fail');
      console.log(errMsg + '失败');
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('加载更多');
    var that = this;
    that.data.pageNum++;
    console.log(that.data.pageNum);
    that.getData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})